package com.xingkeduo.business.order.controller;

import com.xingkeduo.business.order.service.CommentsService;
import com.xingkeduo.dto.*;
import com.xingkeduo.dto.param.CommentsQueryDto;
import com.xingkeduo.dto.param.QueryByUserIdDto;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xingkeduo.utils.Constant.CMS_URL_PREFIX;

/**
 * @author chi  2019-02-13 15:10
 **/
@RestController
@RequestMapping(CMS_URL_PREFIX + "/comments")
@Slf4j
public class CommentsCmsController {

    @Resource
    private CommentsService commentsService;

    /**
     * 分页查询
     * @return
     */
    @GetMapping
    public ResponseEntity get(CommentsQueryDto commentsQueryDto){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.selectListPage(commentsQueryDto)), HttpStatus.OK);
    }

    /**
     * 根据id获得详情
     * @return
     */
    @GetMapping("/query/{commentsId}")
    public ResponseEntity get(@PathVariable String commentsId){
        CommentsResponseDto commentsResponseDto = commentsService.queryById(commentsId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsResponseDto), HttpStatus.OK);
    }


    /**
     * 评价展示设置
     * @return
     */
    @PostMapping("/shown")
    public ResponseEntity showConfig(@RequestBody @Valid CommentsShownDto commentsShownDto){
        log.info("comments showConfig:{}", commentsShownDto);
        commentsService.showConfig(commentsShownDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 评论失效
     * @return
     */
    @PostMapping("/invalid/{commentsId}")
    public ResponseEntity invalid(@PathVariable String commentsId){
        log.info("comments invalid:{}", commentsId);
        commentsService.invalid(commentsId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 评价记录列表展示
     * @return
     */
    @GetMapping("/query/user")
    public ResponseEntity queryCommentsByUserId(@Valid QueryByUserIdDto queryByUserIdDto){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.queryCommentsByUserId(queryByUserIdDto)), HttpStatus.OK);
    }
}
























